package com.panshi.modules.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateFormat {

    public static String dateformat(Date time){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createDate = time+"";
        String createTime = sdf.format(time);
        Date date = null;
        try {
            date = sdf.parse(createTime);
            long differenceValue = new Date().getTime() - date.getTime();
            if(differenceValue < 3600000){
                if((differenceValue / 1000 / 60 )==0){
                    createDate = "刚刚";
                }else{
                    createDate = (differenceValue / 1000 / 60 ) + "分钟前";
                }

            }else if(differenceValue > 3600000){
                if(differenceValue < 86400000){
                    createDate = (differenceValue / 1000 / 60 / 60 ) + "小时前";
                }else{
                    createDate = sdf.format(time);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return createDate;
    }

}
